package com.xsomnus.network_programming.netty.bytebuf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.util.ReferenceCountUtil;

/**
 * @author 叶小夏
 * @since 2019-08-22 09:45
 */
public class ByteBufPlayground {


    private static void test1() {
        ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer(32);
        byte[] bytes = "Hello".getBytes();
        byteBuf.writeBytes(bytes);
        System.out.println(byteBuf.refCnt());
        ReferenceCountUtil.release(byteBuf);
        System.out.println(byteBuf.refCnt());
//        byte[] bytes2 = "World".getBytes();
//        byteBuf.writeBytes(bytes2);
//        System.out.println(byteBuf.refCnt());
//        System.gc();
//        System.out.println(byteBuf == null);
    }


    public static void main(String[] args) {
        test1();
    }

}
